var app = getApp(),
    count = 0,
    imgArray = [],
    siteinfo = require("../../../siteinfo.js");

Page({
    data: {
        stars: [0, 1, 2, 3, 4],
        normalSrc: "../../img/no-star.png",
        selectedSrc: "../../img/full-star.png",
        key: 0,
        count: 0,

        stars1: [0, 1, 2, 3, 4],
        normalSrc1: "../../img/no-star.png",
        selectedSrc1: "../../img/full-star.png",
        key1: 0,
        count1: 0,

        images: [],
        sctp: !1
    },
    sctp: function() {
        this.setData({
            sctp: !0
        });
    },
    selectLeft1: function(t) {
        var o = t.currentTarget.dataset.key;
        1 == this.data.key &&
            1 == t.currentTarget.dataset.key && (o = 0),
            count = o,
            this.setData({
                key: o,
                count: count
            });
    },
    selectLeft2: function(t) {
        var o = t.currentTarget.dataset.key1;
        1 == this.data.key &&
            1 == t.currentTarget.dataset.key1 && (o = 0),
            count = o,
            this.setData({
                key1: o,
                count1: count
            });
    },
    onLoad: function(t) {
        app.setNavigationBarColor(this);
        var o = this,
            e = wx.getStorageSync("users");
        o.setData({
            order_id: t.oid,
            idx: t.indexs,
            detail: t.detail
        });
        wx.showLoading({
            title: "正在加载",
            mask: !0
        });
        app.util.request({
            url: "entry/wxapp/OrderInfo",
            data: {
                order_id: t.oid
            },
            success: function(t) {
                o.setData({
                    good: t.data.good,
                    orderinfo: t.data
                });
            }
        });
    },
    contentInput: function(t) {
        this.setData({
            pjnr: t.detail.value
        });
    },
    chooseImage: function(t) {
        var o = this,
            e = this.data.images,
            a = e.length;
        wx.chooseImage({
            count: 9 - a,
            success: function(t) {
                e = e.concat(t.tempFilePaths), o.setData({
                    images: e
                });
            }
        });
    },
    deleteImage: function(t) {
        var o = t.currentTarget.dataset.index,
            e = this.data.images;
        e.splice(o, 1),
            this.setData({
                images: e
            });
    },
    commentSubmit: function(t) {
        var ths = this,
            o = wx.getStorageSync("users").id,
            e = this.data.orderinfo.store.id,
            a = this.data.orderinfo.order.id,
            n = this.data.pjnr,
            s = this.data.count,
            fw = this.data.count1,
            i = this.data.images;
        if (0 == s)
            wx.showModal({
                title: "提示",
                content: "请选择评分"
            });
        else if (null == n || "" == n) wx.showModal({
            title: "提示",
            content: "请输入评价内容"
        });
        else {
            var c = function() {
                app.util.request({
                    url: "entry/wxapp/Assess",
                    cachetime: "0",
                    data: {
                        store_id: e,
                        user_id: o,
                        order_id: a,
                        stars: s,
                        fw_stars: fw,
                        content: n,
                        img: imgArray.toString()
                    },
                    success: function(t) {
                        "1" == t.data && (wx.showModal({
                            title: "提示",
                            content: "提交成功",
                            success: function() {
                                if (ths.data.detail) {
                                    wx.setStorageSync("order_Refresh", true);
                                    wx.setStorageSync("idx", ths.data.detail);
                                } else {
                                    wx.setStorageSync("idx", ths.data.idx);
                                }
                                wx.navigateBack();
                            }
                        }));
                    }
                });
            };
            wx.showLoading({
                title: "正在提交",
                mask: !0
            }), 0 == i.length ? c() : function t(o) {
                var e = o.i ? o.i : 0,
                    a = o.success ? o.success : 0,
                    n = o.fail ? o.fail : 0;
                wx.uploadFile({
                    url: o.url,
                    filePath: o.path[e],
                    name: "upfile",
                    formData: null,
                    success: function(t) {
                        "" != t.data ? (a++, imgArray.push(t.data)) : wx.showToast({
                            icon: "loading",
                            title: "请重试"
                        });
                    },
                    fail: function(t) {
                        n++;
                    },
                    complete: function() {
                        ++e == o.path.length ? (wx.hideToast(), c()) : (o.i = e, o.success = a, o.fail = n, t(o));
                    }
                });
            }({
                url: siteinfo.siteroot + "?i=" + siteinfo.uniacid + "&c=entry&a=wxapp&do=upload&m=zh_cjdianc",
                path: i
            });
        }
    }
});